<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://xmlns.jcp.org/jsf/html"
	xmlns:f="http://xmlns.jcp.org/jsf/core"
	xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
	xmlns:c="http://xmlns.jcp.org/jsf/composite"
	xmlns:p="http://primefaces.org/ui">

<ui:decorate template="/jsp/WEB/pageLayout.xhtml">

	<ui:define name="centro">
		<h:form id="form">
			<p:growl id="msgs" showDetail="true" />


			<p:panel id="Cadastrar" header="Gerenciar Cartão">

				<br />
				<h:outputLabel
					value="Incluir novo registro ou atualizar cartão existente." />
				<h:panelGrid id="cadCard" columns="3" value="#{CadCardBean.card}"
					style="margin-top:5px" var="card" rowIndexVar="rowIndex">

					<h:outputLabel value="Nº cartão : " />
					<p:inputText value="#{CadCardBean.card.idCard}" />
					<p:commandButton id="searchButton" image="ui-icon-search"
						update="@all" ajax="false" title="Consultar Cartão"
						actionListener="#{CadCardBean.validaBusca}" />
				</h:panelGrid>
				
				<h:panelGrid columns="2" value="#{CadCardBean.card}"
					style="margin-top:5px" var="card" rowIndexVar="rowIndex">

					<h:outputLabel value="Nº identificação do cartão : " />
					<p:inputText value="#{CadCardBean.card.numero}" />

					<h:outputLabel value="Situação:" />
					<p:selectOneMenu id="Situacao" styleClass="dlgTitulo"
						value="#{CadCardBean.card.situacao}" style="width:173px">
						<f:selectItem itemLabel="Escolha a opção: " itemValue=""
							noSelectionOption="true" />
						<f:selectItem itemLabel="Não ativo" itemValue="inativo" />
						<f:selectItem itemLabel="Ativo" itemValue="ativo" />
						<f:selectItem itemLabel="Bloqueado" itemValue="bloqueado" />
						<f:selectItem itemLabel="Eliminado" itemValue="eliminado" />
					</p:selectOneMenu>

					<h:outputLabel value="Observação : " />
					<p:inputTextarea value="#{CadCardBean.card.obs}" />
				</h:panelGrid>
				<p:separator />

				<p:commandButton id="salvar" value="Gravar" update="@form"
					ajax="false" icon="ui-icon-plusthick"
					title="Incluir novo cartão ou atualizar"
					action="#{CadCardBean.checkCard}" />
			</p:panel>


			<p:panel id="Listas" header="Listagem de Cartões" style="margin-top:5%">
				<p:dataTable id="listaCards" var="cards"
					value="#{CadCardBean.cardList}"
					emptyMessage="Nenhum cartão encontrado!"
					style="margin-top:20px; position: auto" paginator="true"
					selectionMode="single" selection="#{CadCardBean.cards}"
					rowKey="#{cards.idCard}">
					<p:ajax event="rowSelect" update=":form:cadCard"
						listener="#{CadCardBean.show()}" />

					<p:column style="width: 50px;" sortBy="idCard">
						<f:facet name="header">Nº cartão</f:facet>
						<h:outputText value="#{cards.idCard}" />
					</p:column>

					<p:column style="width: 50px;" sortBy="numero">
						<f:facet name="header">Nº identificação cartão</f:facet>
						<h:outputText value="#{cards.numero}" />
					</p:column>

					<p:column style="width: 50px;" sortBy="situacao">
						<f:facet name="header">Situação</f:facet>
						<h:outputText value="#{cards.situacao}" />
					</p:column>

				</p:dataTable>
			</p:panel>
		</h:form>

		<p:confirmDialog id="confirmaAlteracao"
			message="Confirma alteração deste cartão?" header="Confirmação"
			severity="alert" widgetVar="confirmaAlteracao" modal="true"
			appendTo="@(body)">
			<h:form>
				<p:commandButton id="confirmaBtn" value="Sim"
					onclick="confirmaAlteracao.hide()"
					action="#{CadCardBean.updateCard}" ajax="false"
					icon="ui-icon-check">
				</p:commandButton>
				<p:commandButton id="recusaBtn" value="Não"
					onclick="confirmaAlteracaoo.hide()" icon="ui-icon-close" />
			</h:form>
		</p:confirmDialog>

	</ui:define>
</ui:decorate>
</html>
